package com.mju;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import com.alibaba.excel.EasyExcel;
import com.mju.dao.UsersMapper;
import com.mju.service.TeacherService;

import lombok.Data;

@SpringBootTest
class EptGenMsgData {
	
	@Value("${custom.choiceRedisKey}")
	private String choiceRedisKey;

	@Autowired
	private TeacherService teacherService;
	
	@Autowired
	private UsersMapper usersMapper;

 	
	//测试模拟生成所有学生发送消息，用于测试
	@Test
	public void testAllSend() {
		List<String> students= usersMapper.selectByRole("student");
		List<String> teachers= usersMapper.selectByRole("teacher");
		
		List<TestData> result=new ArrayList<>();
		int total=teachers.size();
		
		Random r=new Random();

		for(String s:students) {
			try {
				int t1=r.nextInt(total);
				int t2=r.nextInt(total);
				
				TestData t=new TestData(s,teachers.get(t1),
						teachers.get(t2),(new Date()).getTime());
				result.add(t);
				teacherService.sendStreamMsg(s, teachers.get(t1),teachers.get(t2));
				Thread.sleep(1000);
			}
			catch(Exception ex) {
				System.out.println(ex.getMessage());
				continue;
			}
		}
		//导出Excel表
		EasyExcel.write("D:\\AllStudentRedis.xlsx", TestData.class)
        .sheet("Sheet1") // 指定工作表名称
        .doWrite(result); // 将数据列表写入Excel
	}
}

@Data
class TestData{
	private String studentno;
	private String teacher1;
	private String teacher2;
	private Long selectTime;
	public TestData() {
		
	}
	public TestData(String studentno,String teacher1
			,String teacher2,Long selectTime) {
		this.studentno=studentno;
		this.teacher1=teacher1;
		this.teacher2=teacher2;
		this.selectTime=selectTime;
	}
}